/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.knolle.menu;

import java.util.List;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.nodes.ChildFactory;
import org.openide.windows.TopComponent;
import org.openide.util.NbBundle.Messages;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//org.knolle.menu//VentanaMenu//EN",
autostore = false)
@TopComponent.Description(preferredID = "VentanaMenuTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE", 
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "leftSlidingSide", openAtStartup = true)
@ActionID(category = "Window", id = "org.knolle.menu.VentanaMenuTopComponent")
@ActionReference(path = "Menu/Window" /*
 * , position = 333
 */)
@TopComponent.OpenActionRegistration(displayName = "#CTL_VentanaMenuAction",
preferredID = "VentanaMenuTopComponent")
@Messages({
    "CTL_VentanaMenuAction=VentanaMenu",
    "CTL_VentanaMenuTopComponent=VentanaMenu Window",
    "HINT_VentanaMenuTopComponent=This is a VentanaMenu window"
})
public final class VentanaMenuTopComponent extends TopComponent {

    public VentanaMenuTopComponent() {
        initComponents();
        setName(Bundle.CTL_VentanaMenuTopComponent());
        setToolTipText(Bundle.HINT_VentanaMenuTopComponent());

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        beanTreeView1 = new org.openide.explorer.view.BeanTreeView();

        jScrollPane1.setViewportView(beanTreeView1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.openide.explorer.view.BeanTreeView beanTreeView1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
        //Invocar los metodos de creacion del menu
        //pasar los items al BeanTree
        //
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }
    
    private class MenuChildFactory extends ChildFactory<Menu> {
        
        private List<Menu> menuList;

        public MenuChildFactory(List<Menu> menuList) {
            this.menuList = menuList;
        }
        
        

        @Override
        protected boolean createKeys(List<Menu> list) {
//            throw new UnsupportedOperationException("Not supported yet.");
            for (Menu menu : menuList){
                list.add(menu);
            }
            return true;
        }
    
    }
}
